<template>
	<view class="teach-container">
		<view v-if="loading">
			<loading></loading>
		</view>
		<view class="detail" v-else>
			<view class="top-button">
				<button size="mini" @click="addCourse()">新增课程</button>
				<!-- <button size="mini" @click="addCate()">创建类目</button> -->
			</view>
			<view class="course" v-for="(item, index) in tableData" :key="index" @click="open(item)">
				<view class="left">
					<image :src="item.imgUrl" mode="widthFix"></image>
				</view>
				<view class="right">
					<view class="title">
						<text class="name">{{item.knowledgeName}}</text>
						<text>访问量：{{item.count}}</text>
					</view>
					<view class="desc">
						<text>创建时间:{{parseTime(item.createTime,'{y}-{m}-{d}')}}</text>
						<!-- <text class="green">{{ item.isShow == 0?'首页展示':'首页不展示' }}</text> -->
						<text class="red">{{item.isPulice == 1?'公开':'私有'}}</text>
					</view>
				</view>
			</view>
			<view class="load-more">
				<uni-icons v-if="loadShow" type="spinner-cycle" size="30"></uni-icons>
				<text  v-if="botShow">已经到底了</text>
			</view>
			<view >
				<button class="bottom-button" size="mini" @click="addCourse()">新增课程</button>
				<!-- <button size="mini" @click="addCate()">创建类目</button> -->
			</view>
		</view>
		<uni-popup ref="popup" type="bottom">
			<view class="popup">
				<text @click="update">修改</text>
				<text  @click="delet" class="del">删除</text>
				<text class="cancel" @click="close">取消</text>
			</view>
		</uni-popup>
	</view>
</template>
<script>
	import { getCourseListAdmin,delCourse} from '@/api/exam/activity.js'
	import loading from '@/components/loading/loading'
	import {parseTime } from '@/utils/ruoyi'
	export default {
		data() {
			return {
				tableData: [],
				pageForm:{
					pageNo:1,
					pageSize:10,
				},
				parseTime,
				loadShow:false,
				botShow:false,
				loading:true,
			}
		},
		onLoad(e) {
			this.categoryId = e.id
		},
		onShow() {
			this.tableData=[]
			this.getList();
		},
		onReachBottom(){
			if(!this.botShow){
				this.loadShow = true
				this.pageForm.pageNo ++ ;
				this.getList()
			}
			
		},
		methods: {
			open(e){
				this.active=e
				// 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ，type 属性将失效 ，仅支持 ['top','left','bottom','right','center']
				this.$refs.popup.open('bottom')
			},
			close() {
				this.$refs.popup.close()
			},
			addCourse(){
				this.close()
				this.$tab.navigateTo('/pages/work/teach/addCourse?categoryId=' + this.categoryId)
			},
			getList(){
				this.pageForm.categoryId=this.categoryId 
				getCourseListAdmin(this.pageForm).then(res=>{
					// this.tableData=res.data.list
					if(res.data.list.length > 0){
						this.tableData.push(...res.data.list)
						this.loadShow = false
					}else{
						this.loadShow = false
						this.botShow = true
					}
					this.loading = false
				})
			},
			update(){
				this.close()
				this.$tab.navigateTo('/pages/work/teach/addCourse?id='+this.active.id)
			},
			clickRecord(e){
				this.$tab.navigateTo('/pages/work/teach/courseRecord?id='+e.id)
			},
			delet(){
				delCourse(this.active.id).then(res=>{
					this.$modal.msgSuccess("删除成功")
					this.tableData = []
					this.getList()
					this.close()
					
				})
			},
		}
	}
</script>

<style lang="scss">
	/* #ifndef APP-NVUE */
	page{
		background: #fff;
	}
	view {
		font-size: 14px;
		line-height: inherit;
	}
	
	/* #endif */
	.teach-container{
		background-color: #fff;
		padding: 40rpx;
		.top-button{
			button{
				border: none;
				padding: 0 20rpx;
				line-height: 50rpx;
				background: #508CFF;
				color: #fff;
				margin-right: 20rpx;
			}
		}
		.detail {
			width: 100%;
			background-color: #fff;
			border-radius: 20rpx;
			.course{
				display: flex;
				justify-content: space-around;
				border-bottom: 1px solid #EDEDED;
				padding: 10px 0;
				align-items: center;
				text{
					line-height: 30px;
					font-size: 12px;
					font-family: Inter-Regular, Inter;
					font-weight: 400;
				}
				.left{
					width: 80px;
					height: 53px;
					overflow: hidden;
				}
				.right{
					width: calc(100% - 80px);
					padding-left: 20px;
					.title{
						display: flex;
						justify-content: space-between;
						text{
							color: #5E5E5E;;
						}
						.name{
							font-size: 14px;
							font-family: Inter-Regular, Inter;
							font-weight: 400;
							color: #000000;
						}
					}
					.desc{
						display: flex;
						justify-content: space-between;
						text{
							padding-right: 8px;
						}
						.green{
							color: #50B987;
						}
						.red{
							color:#FF9A50;
						}
					}
				}
			}
			
		}
		.bottom-button{
			color: #fff;
			width: 100px;
			height: 40px;
			font-size: 14px;
			line-height: 40px;
			background: #508CFF;
			border-radius: 5px 5px 5px 5px;
			position: absolute;
			bottom: 50px;
			left: 36%;
		}
		.load-more{
			display: block;
			padding: 20px;
			margin: 0 auto;
			text-align: center;
		}
		.popup{
			height: 157px;
			background: #FFFFFF;
			text{
				line-height: 50px;
				display: block;
				text-align: center;
				font-family: Roboto-Regular, Roboto;
				font-weight: 400;
				color: #000000;
				font-size: 16px;
			}
			.cancel{
				color: #F26D6D;
			}
		}
	}
</style>